home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / HyperCuber Source / HyperCuber 2.0 Source.sit / HyperCuber 2.0 Source / CEditMouseControlsDialog.cp < prev    next >
Text File  |  1994-05-02  |  10KB  |  259 lines

  1. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  2. //| CEditMouseControlsDialog.cp
  3. //|
  4. //| This implements the dialog used to edit a mouse control
  5. //|_________________________________________________________
  6.  
  7. #include "CEditMouseControlsDialog.h"
  8.  
  9. #include "HyperCuber Balloons.h"
  10. #include "HyperCuber Commands.h"
  11.  
  12. #include <CBartender.h>
  13. #include <CButton.h>
  14. #include <CCheckBox.h>
  15. #include <CDecorator.h>
  16. #include <CEditText.h>
  17. #include <CIntegerText.h>
  18. #include <CPaneBorder.h>
  19. #include <CPopupMenu.h>
  20. #include <CStdPopupPane.h>
  21.  
  22. #include <ctype.h>
  23. #include <string.h>
  24.  
  25. //============================ Globals ===============================\\
  26.  
  27. extern CDecorator         *gDecorator;
  28. extern CBartender         *gBartender;
  29.  
  30.  
  31.  
  32. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  33. //| CEditMouseControlsDialog::IEditMouseControlsDialog
  34. //|
  35. //| Purpose: Initialize the dialog.
  36. //|
  37. //| Parameters: WindowID:      ID of WIND resource to use
  38. //|             enclosure:     the Desktop
  39. //|             supervisor:    the supervisor of this DialogDirector
  40. //|             mouse_control: the mouse control to edit
  41. //|______________________________________________________________________________
  42.  
  43. void CEditMouseControlsDialog::IEditMouseControlsDialog(short WindowID, CDesktop *enclosure,
  44.                                             CDirector *supervisor, mouse_control_struct *mouse_control)
  45. {
  46.  
  47.     
  48. #define OKAY_BUTTON_ID        130
  49. #define CANCEL_BUTTON_ID    131
  50.  
  51. #define FUNCTION_HEIGHT        40
  52. #define DIRECTION_MENU_ID    133
  53. #define DIMENSION_MENU_ID    30000
  54. #define ANGLE_MENU_ID        30001
  55. #define REVERSE_CHECKBOX_ID    129
  56.  
  57. #define COMMAND_CHECKBOX_ID    136
  58. #define OPTION_CHECKBOX_ID    137
  59. #define SHIFT_CHECKBOX_ID    138
  60. #define CONTROL_CHECKBOX_ID    128
  61.  
  62.     CDialog::IDialog(WindowID, enclosure, supervisor);        //  Initialize window from WIND resource
  63.  
  64.     helpResID = WINDOW_HELP_RES;                            //  Link in the Balloon Help
  65.  
  66.     CButton        *button;
  67.     button = new(CButton);                                    //  Set up the okay button
  68.     button->IButton(OKAY_BUTTON_ID, this, this);
  69.     button->Offset(320, FUNCTION_HEIGHT + 40, TRUE);
  70.     button->SetClickCmd (cmdOK);
  71.     button->helpResIndex = kMouseEdOkay;
  72.     SetDefaultButton(button);
  73.     
  74.     button = new (CButton);                                    //  Set up the cancel button
  75.     button->IButton(CANCEL_BUTTON_ID, this, this);
  76.     button->Offset(220, FUNCTION_HEIGHT + 40, TRUE);
  77.     button->SetClickCmd (cmdCancel);
  78.     button->helpResIndex = kMouseEdCancel;
  79.     
  80.     CEditText *text = new(CEditText);                        //  Set up the Modifiers text
  81.     text->IEditText(this, this, 70, 16,
  82.                     0, 10, sizFIXEDLEFT, sizFIXEDTOP, -1);
  83.     text->SetTextString("\pModifiers:");
  84.     text->SetFontNumber(systemFont);
  85.     text->SetFontSize(12);
  86.     text->SetWantsClicks(FALSE);
  87.     text->Specify(kNotEditable, kNotSelectable, kNotStylable);
  88.     text->SetAlignCmd(cmdAlignRight);
  89.     
  90.     command_checkbox = new(CCheckBox);                        //  Set up the command checkbox
  91.     command_checkbox->ICheckBox(COMMAND_CHECKBOX_ID, this, this);
  92.     command_checkbox->Offset(80, 10, TRUE);
  93.     command_checkbox->helpResIndex = kMouseEdCommand;
  94.  
  95.     option_checkbox = new(CCheckBox);                        //  Set up the option checkbox
  96.     option_checkbox->ICheckBox(OPTION_CHECKBOX_ID, this, this);
  97.     option_checkbox->Offset(170, 10, TRUE);
  98.     option_checkbox->helpResIndex = kMouseEdOption;
  99.  
  100.     shift_checkbox = new(CCheckBox);                        //  Set up the shift checkbox
  101.     shift_checkbox->ICheckBox(SHIFT_CHECKBOX_ID, this, this);
  102.     shift_checkbox->Offset(240, 10, TRUE);
  103.     shift_checkbox->helpResIndex = kMouseEdShift;
  104.  
  105.     control_checkbox = new(CCheckBox);                        //  Set up the control checkbox
  106.     control_checkbox->ICheckBox(CONTROL_CHECKBOX_ID, this, this);
  107.     control_checkbox->Offset(300, 10, TRUE);
  108.     control_checkbox->helpResIndex = kMouseEdControl;
  109.  
  110.     text = new(CEditText);                                    //  Set up the "Function:" text
  111.     text->IEditText(this, this, 70, 16,
  112.                     0, FUNCTION_HEIGHT, sizFIXEDLEFT, sizFIXEDTOP, -1);
  113.     text->SetTextString("\pFunction: Track");
  114.     text->SetFontNumber(systemFont);
  115.     text->SetFontSize(12);
  116.     text->SetWantsClicks(FALSE);
  117.     text->Specify(kNotEditable, kNotSelectable, kNotStylable);
  118.     text->SetAlignCmd(cmdAlignRight);
  119.  
  120.     short cursor = 79;
  121.     text = new(CEditText);                                    //  Set up the "Track [" text
  122.     text->IEditText(this, this, 60, 16, cursor, FUNCTION_HEIGHT,
  123.                         sizFIXEDLEFT, sizFIXEDTOP, -1);
  124.     text->SetTextString("\pTrack [");
  125.     text->SetFontNumber(systemFont);
  126.     text->SetFontSize(12);
  127.     text->SetWantsClicks(FALSE);
  128.     text->Specify(kNotEditable, kNotSelectable, kNotStylable);
  129.     cursor += 50;
  130.  
  131.     dimension_text = new(CIntegerText);                        //  Set up the dimension text
  132.     dimension_text->IIntegerText(this, this, 40, 16, 
  133.                         cursor, FUNCTION_HEIGHT,
  134.                             sizFIXEDLEFT, sizFIXEDTOP, -1);
  135.     dimension_text->SetFontNumber(systemFont);
  136.     dimension_text->SetFontSize(12);
  137.     dimension_text->SpecifyDefaultValue(3);
  138.     dimension_text->helpResIndex = kMouseEdDimension;
  139.     cursor += 44;
  140.  
  141.     text = new(CEditText);                                    //  Set up the : text
  142.     text->IEditText(this, this, 100, 16, cursor, FUNCTION_HEIGHT,
  143.                         sizFIXEDLEFT, sizFIXEDTOP, -1);
  144.     text->SetTextString("\p:");
  145.     text->SetFontNumber(systemFont);
  146.     text->SetFontSize(12);
  147.     text->SetWantsClicks(FALSE);
  148.     text->Specify(kNotEditable, kNotSelectable, kNotStylable);
  149.     cursor += 10;
  150.  
  151.     angle_text = new(CDialogText);                            //  Set up the angle text
  152.     angle_text->IDialogText(this, this, 40, 16, 
  153.                         cursor, FUNCTION_HEIGHT,
  154.                             sizFIXEDLEFT, sizFIXEDTOP, -1);
  155.     angle_text->SetFontNumber(systemFont);
  156.     angle_text->SetFontSize(12);
  157.     angle_text->helpResIndex = kMouseEdAngle;
  158.     cursor += 44;
  159.  
  160.     text = new(CEditText);                                    //  Set up the "]" text
  161.     text->IEditText(this, this, 100, 16, cursor, FUNCTION_HEIGHT,
  162.                         sizFIXEDLEFT, sizFIXEDTOP, -1);
  163.     text->SetTextString("\p]");
  164.     text->SetFontNumber(systemFont);
  165.     text->SetFontSize(12);
  166.     text->SetWantsClicks(FALSE);
  167.     text->Specify(kNotEditable, kNotSelectable, kNotStylable);
  168.     cursor += 20;
  169.  
  170.     direction_popup = new (CStdPopupPane);                    //  Set up the direction menu
  171.     direction_popup->IStdPopupPane(
  172.                             DIRECTION_MENU_ID, this, this,
  173.                             kAutoSize, kAutoSize, cursor, FUNCTION_HEIGHT);
  174.     direction_popup->helpResIndex = kMouseEdDirection;
  175.  
  176.     multiplier_text = new(CIntegerText);                    //  Set up the editable multiplier text
  177.     multiplier_text->IIntegerText(this, this, 60, 16, 
  178.                         130, FUNCTION_HEIGHT+30,
  179.                             sizFIXEDLEFT, sizFIXEDTOP, -1);
  180.     multiplier_text->SetFontNumber(systemFont);
  181.     multiplier_text->SetFontSize(12);
  182.     multiplier_text->SpecifyDefaultValue(1);
  183.     multiplier_text->helpResIndex = kMouseEdMultiplier;
  184.  
  185.     text = new(CEditText);                                    //  Set up the x text
  186.     text->IEditText(this, this, 10, 16,
  187.                     115, FUNCTION_HEIGHT+32, sizFIXEDLEFT, sizFIXEDTOP, -1);
  188.     text->SetFontNumber(monaco);
  189.     text->SetFontSize(9);
  190.     text->SetTextString("\px");
  191.     text->SetWantsClicks(FALSE);
  192.     text->Specify(kNotEditable, kNotSelectable, kNotStylable);
  193.  
  194.     direction_popup->GetMenu()->SelectItem(mouse_control->horiz + 1,
  195.                                             pmForceOn);                //  Set the direction checkbox
  196.  
  197.     multiplier_text->SetIntValue(mouse_control->multiplier);        //  Set increment
  198.     dimension_text->SetIntValue(mouse_control->dimension);            //  Set the dimension
  199.  
  200.     if (mouse_control->angle == 0)
  201.         angle_text->SetTextString("\pP");                            //  Set perspective change
  202.     else
  203.         {
  204.         Str255 angle_string;
  205.         NumToString(mouse_control->angle, angle_string);
  206.         angle_text->SetTextString(angle_string);                    //  Set the angle text
  207.         }
  208.  
  209.     command_checkbox->SetValue(mouse_control->modifiers & cmdKey);        //  Set the command checkbox
  210.     control_checkbox->SetValue(mouse_control->modifiers & controlKey);    //  Set the control checkbox
  211.     option_checkbox->SetValue(mouse_control->modifiers & optionKey);    //  Set the option checkbox
  212.     shift_checkbox->SetValue(mouse_control->modifiers & shiftKey);        //  Set the shift checkbox
  213.  
  214.     gDecorator->CenterWindow (this);                                //  Center the window on the screen
  215.  
  216. }    //=== CEditMouseControlsDialog::IEditMouseControlsDialog() ===\\
  217.  
  218.  
  219.  
  220. //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  221. //| CEditMouseControlsDialog::UpdateMouseControl
  222. //|
  223. //| Purpose: Sets the mouse control to match the settings chosen in the dialog.
  224. //|
  225. //| Parameters: mouse_control: receives the settings chosen in the dialog
  226. //|______________________________________________________________________________
  227.  
  228. void CEditMouseControlsDialog::UpdateMouseControl(mouse_control_struct *mouse_control)
  229. {
  230.  
  231.     mouse_control->modifiers = 0;                                            //  Build the modifiers
  232.     if (command_checkbox->GetValue()) mouse_control->modifiers |= cmdKey;
  233.     if (option_checkbox->GetValue()) mouse_control->modifiers |= optionKey;
  234.     if (shift_checkbox->GetValue()) mouse_control->modifiers |= shiftKey;
  235.     if (control_checkbox->GetValue()) mouse_control->modifiers |= controlKey;
  236.  
  237.     mouse_control->horiz =
  238.                 (direction_popup->GetMenu()->GetCheckedItem() - 1);            //  Get the direction
  239.  
  240.     mouse_control->dimension = dimension_text->GetIntValue();                //  Get the dimension
  241.     mouse_control->multiplier = multiplier_text->GetIntValue();                //  Get the multiplier
  242.  
  243.     Str255 angle_string;
  244.     angle_text->GetTextString(angle_string);                        //  Get the angle as a string
  245.     if ((angle_string[0] == '\1') &&
  246.             (toupper(angle_string[1]) == 'P'))
  247.         mouse_control->angle = 0;                                    //  Perspective change
  248.     else
  249.         {
  250.         long angle_long;
  251.         StringToNum(angle_string, &angle_long);                        //  Convert to number
  252.         if (angle_long >= mouse_control->dimension)
  253.             angle_long = mouse_control->dimension - 1;                //  Clip to dimension
  254.         if (angle_long <= 0)
  255.             angle_long = 1;                                            //  Clip to angle == 1
  256.         mouse_control->angle = angle_long;
  257.         }
  258.  
  259. }    //==== CEditMouseControlsDialog::UpdateMouse() ====\\